package com.ssm.dao;

import com.ssm.domain.Permission;
import com.ssm.domain.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface RoleDao {
    @Select("select role.*\n" +
            "from role right join users_role ur on role.id = ur.roleId where USERID=#{i}")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "roleName",column = "roleName"),
            @Result(property = "roleDesc",column = "roleDesc"),
            @Result(property = "permissions" ,column = "id" ,javaType = List.class,many = @Many(select = "com.ssm.dao.PermissionDao.findByRoleId"))
    })
    List<Role> findByUserId(String id);

    @Select("select * from role")
    List<Role> findAll();

    @Insert("insert into role(ROLENAME,ROLEDESC) values(#{roleName},#{roleDesc})")
    void save(Role role);

    @Select("select * from role where id = #{o}")
    Role findById(String id);

    @Select("select  * from PERMISSION  where id not in (select PERMISSIONID from ROLE_PERMISSION where ROLEID=#{i}) ")
    List<Permission> findOtherPerm(String id);

    @Insert("insert into ROLE_PERMISSION(roleid,permissionid) values(#{param1},#{param2})")
    void addPermToRole(String id, String s);
}









